module Hw1 where
import SOE
import Play
import XMLTypes

data Shape = Rectangle Side Side
           | Ellipse Radius Radius
           | RtTriangle Side Side
           | Polygon [Vertex]
           deriving Show

type Radius = Float 
type Side   = Float
type Vertex = (Float, Float)

-- Part 1.1 --
rectangle :: Side -> Side -> Shape
rectangle sideA sideB = Polygon [(0,0), (sideA,0), (sideA,sideB), (0,sideB)] 

rtTriangle :: Side -> Side -> Shape
rtTriangle sideA sideB = Polygon [(0,0), (sideA,0), (0, sideB)]

-- Part 1.2 --
sides :: Shape -> Int
sides (Ellipse r1 r2)    = 42
sides (Rectangle s1 s2)  = sides (rectangle s1 s2)
sides (RtTriangle s1 s2) = sides (rtTriangle s1 s2)
sides (Polygon vList)    = if (length vList <= 2) 
                           then 0
                           else (length vList)
-- Part 1.3 --
bigger :: Shape -> Float -> Shape
bigger (Ellipse r1 r2) n    = Ellipse ((sqrt n)*r1) ((sqrt n)*r2)
bigger (Rectangle s1 s2) n  = bigger (rectangle s1 s2) n
bigger (RtTriangle s1 s2) n = bigger (rtTriangle s1 s2) n
bigger (Polygon vList) n    = let s = sqrt n
                              in Polygon (map (\(a,b) -> (a*s,b*s)) vList) 

-- Part 1.4 --

replaceNth n newVal (x:xs)
     | n == 0    = newVal:xs
     | otherwise = x:replaceNth (n-1) newVal xs

--move :: Int -> Int -> Int -> Int -> [a] -> IO ()
move 1 a b tmp list = do let list = replaceNth a (list!!a - 1) list
                         return replaceNth b (list!!b + 1) list
                         --return [0,0,0]

move n a b tmp list = do move (n-1) a tmp b list
                         move 1 a b tmp list
                         move (n-1) tmp b a list

--hanoi :: Int -> String -> String -> String -> IO ()
--hanoi n a b c = do 
--               let discs = [n,0,0]
--                
--               putStrLn "hanoi"


-- Part 2.1 --
sierpinskiCarpet :: IO ()
sierpinskiCarpet = error "Define me!"

